﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using Gfw.BLL.Basic.ExceptionImpl;
//using Gfw.BLL.Basic.Facilities;
//using Gfw.BLL.Basic.Stock.Enums;
//using Gfw.Models.Stock;
//using Gfw.Repositories.Stock;
//using Gfw.Repository;
//using Gfw.Stock.Base;

//namespace Gfw.BLL.Basic.Stock.Facilities
//{
//   public class CancelTradeFacility:IFacility
//    {
//       private StkWaitbargainpool _agencyPool;

//       public CancelTradeFacility(StkWaitbargainpool agencyPool)
//       {
//           _agencyPool = agencyPool;
//       }

//       public void Execute(Repository.UnitOfWork unitOfWork = null)
//        {
//            if (unitOfWork != null)
//                throw new GfwTransactionInvalidException("撤单事务只能作为原子操作。");
//           UnitOfWork work = new UnitOfWork();
//            //执行撤单操作，删除Pool，
//           _agencyPool.AgencyCount = 0;
//           WaitBargainPoolRepository poolRep = new WaitBargainPoolRepository();
//           poolRep.Delete(_agencyPool.Id,work);

//           //修改委托状态
//           BargainAgencyRepository agencyRep = new BargainAgencyRepository();
//          var agency = agencyRep.Get(_agencyPool.AgencyId);
//           agency.TradeStatus = (int) TradeStatusEnum.Done;
//           agencyRep.Update(agency, work);

//           //增加撤单的交易记录
//           StkBargainrecord record = new StkBargainrecord()
//           {
//               Id = Guid.NewGuid().ToString(),
//               ActualCount = 0,
//               ActualPrice = agency.AgencyPrice,
//               AgencyCount = agency.AgencyCount,
//               AgencyId = agency.Id,
//               AgencyPrice = agency.AgencyPrice,
//               AwardSerialNo =
//                   agency.TradeType == (int)TradeTypeEnum.Sell
//                       ? Guid.NewGuid().ToString()
//                       : "",
//               BargainDate = DateTime.Now,
//               BargainType = (int)TradeTypeEnum.Cancel,
//               TotalPrice = 0,
//               Userid = agency.Userid,
//               Income = 0,
//               Taxation = 0
//           };

//           BargainRecordRepository recordRep = new BargainRecordRepository();
//           recordRep.Save(record, work);

//           work.Commit();


//        }
//    }
//}
